package com.erplan.swt.app.gx.db;

import java.sql.*;

import com.erplan.swt.app.gx.Gx;

public class ManageAppData {

	public static long GetIntData (String parameter) {
		long data = 0;
		ResultSet rs = null;
		try {
			PreparedStatement ps = Gx.db.prepareStatement("SELECT * FROM tblappdata WHERE description = ?");
			ps.setString(1,parameter);
			rs = ps.executeQuery();
			rs.next();

			data = rs.getLong("int_value");
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}

	public static void SaveIntData (String parameter , long data) {
		try {
			PreparedStatement ps = Gx.db.prepareStatement("UPDATE tblappdata SET int_value = ? WHERE description = ?");
			ps.setLong(1,data);
			ps.setString(2,parameter);
			ps.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static String GetStringData (String parameter) {
		String data = null;
		ResultSet rs = null;
		try {
			PreparedStatement ps = Gx.db.prepareStatement("SELECT * FROM tblappdata WHERE description = ?");
			ps.setString(1,parameter);
			rs = ps.executeQuery();
			rs.next();

			data = rs.getString("string_value");

		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}

	public static void SaveStringData (String parameter , String data) {
		try {
			PreparedStatement ps = Gx.db.prepareStatement("UPDATE tblappdata SET string_value = ? WHERE description = ?");
			ps.setString(1,data);
			ps.setString(2,parameter);
			ps.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}